package pub.wkq.work.service.impl;

import org.springframework.transaction.annotation.Transactional;
import pub.wkq.common.exception.CustomException;
import pub.wkq.common.result.ResponseStatusEnum;
import pub.wkq.pojo.Resume;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pub.wkq.work.mapper.ResumeMapper;
import pub.wkq.work.service.ResumeService;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 简历表 服务实现类
 * </p>
 *
 * @author 王开琦
 * @since 2023-06-05
 */
@Service
public class ResumeServiceImpl implements ResumeService {
    @Resource
    private ResumeMapper resumeMapper;

    @Override
    @Transactional
    public void initResume(String userId) {
        Resume resume = new Resume();
        resume.setUserId(userId);
        resume.setCreateTime(LocalDateTime.now());
        resume.setUpdatedTime(LocalDateTime.now());
        int insert = resumeMapper.insert(resume);
//        int a = 1 / 0; // 测试分布式事务
        if (insert != 1) {
            throw new CustomException(ResponseStatusEnum.RESUME_INIT_ERROR);
        }
    }
}
